<h1 class="page-header">
    <small>新增会员</small>
</h1>
<hr/>
<div class="panel panel-inverse" data-sortable-id="form-stuff-1">
    <div class="panel-heading">
        <h4 class="panel-title">会员信息</h4>
    </div>
    <div class="panel-body">
        <form class="form-horizontal" id="memberForm" name="memberForm" method="post">
            <div class="form-group">
                <label class="col-md-3 control-label"><span class="requiredstar">* </span>等级：</label>
                <div class="col-md-3">
                    <select class="form-control" id="gradeId" name="gradeId">
                        <#list userGradeMap as grade>
                        <option value="${grade.id}">${grade.name}</option>
                        </#list>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">手机号：</label>
                <div class="col-md-3">
                    <input type="text" id="mobile" class="form-control" name="mobile" placeholder="手机号">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label"><span class="requiredstar">* </span>名称：</label>
                <div class="col-md-3">
                    <input type="text" id="name" class="form-control" name="name" placeholder="名称最长20位" maxlength="20" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">性别：</label>
                <div class="col-md-3">
                    <select class="form-control" name="sex" id="sex">
                        <option value="1">男</option>
                        <option value="2">女</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">身份证：</label>
                <div class="col-md-3">
                    <input type="text" id="idcard" class="form-control" name="idcard" placeholder="身份证号码" maxlength="30" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">生日：</label>
                <div class="col-md-3">
                    <input type="text" id="birthday" class="form-control" name="birthday" placeholder="生日，如：1998-10-30" maxlength="20" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">初始积分：</label>
                <div class="col-md-3">
                    <input type="text" id="point" class="form-control" name="point" value="0" placeholder="初始积分，正整数" maxlength="20" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">通讯地址：</label>
                <div class="col-md-5">
                    <input type="text" id="address" class="form-control" name="address" placeholder="通讯地址" maxlength="20" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">状态：</label>
                <div class="col-md-3">
                    <select class="form-control" name="status" id="status">
                        <option value="A">激活</option>
                        <option value="D">禁用</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">备注信息：</label>
                <div class="col-md-5">
                    <textarea rows="5" class="form-control" id="description" name="description" maxlength="500" placeholder="备注信息"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label"></label>
                <div class="col-md-9">
                    <button type="button" id="submitButton" class="btn btn-sm btn-success">提交</button>
                    <button type="button" class="btn btn-sm btn-danger"
                            onclick="getData('${rc.contextPath}/backend/member/queryList', 'displayArea')">返回
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="application/javascript">

    jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "请正确填写手机号码");

    $(function () {
        $('#submitButton').click(function () {
            if ($("#mobile").val() != null || $("#mobile").val() != "") {
                $('#memberForm').submit();
            }
        });

        $('#memberForm').validate({
            rules: {
                mobile: {
                    required : true,
                    minlength : 11,
                    isMobile : true
                }

             },
            messages: {
                mobile: {
                    required : "请输入手机号",
                    minlength : "不能小于11个字符",
                    isMobile : "请正确填写手机号码"
                }
            },
            errorPlacement: function (error, element) {
                error.appendTo(element.parent());
            },
            submitHandler: function () {
                postDataByFormParams('${rc.contextPath}/backend/member/create', 'displayArea', 'memberForm');
            }
        })
    })
</script>

